﻿using System.IO;
using MediaBrowserSL.BLL.Contexts;
using MediaBrowserSL.BOL;
using MediaBrowserSL.IBLL;
using MediaBrowserSL.IDAL;

namespace MediaBrowserSL.BLL
{
    /// <summary>
    /// Authentification Manager
    /// </summary>
    public class AuthenticationManager : IAuthenticationManager
    {
        private IUserRepository userRepository;

        public AuthenticationManager(IUserRepository userRepository)
        {
            this.userRepository = userRepository;
        }

        /// <summary>
        /// Exist User
        /// </summary>
        /// <param name="Login"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public User ExistUser(string Login)
        {
            return userRepository.ExistUser(Login);
        }

        /// <summary>
        /// Create new User
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="Login"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public int CreateUser(string firstName, string lastName, string Login, string password)
        {
            string urlCat1 = PathMediaContext.DirPathMedia + "/" + Login + "/1/";
            string urlCat2 = PathMediaContext.DirPathMedia + "/" + Login + "/2/";
            string urlCat3 = PathMediaContext.DirPathMedia + "/" + Login + "/3/";
            string urlCat4 = PathMediaContext.DirPathMedia + "/" + Login + "/4/";

            Directory.CreateDirectory(urlCat1);
            Directory.CreateDirectory(urlCat2);
            Directory.CreateDirectory(urlCat3);
            Directory.CreateDirectory(urlCat4);            

            return userRepository.CreateUser(firstName, lastName, Login, password);
        }

         /// <summary>
        /// Update Statut User
        /// </summary>
        /// <param name="u"></param>
        public void UpdateStatut(User u)
        {
            userRepository.UpdateStatut(u);
        }

        /// <summary>
        /// Exist Login
        /// </summary>
        /// <param name="Login"></param>
        /// <returns></returns>
        public bool ExistLogin(string Login)
        {
            return userRepository.ExistLogin(Login);
        }
    }
}
